AEL COMPUTER SCIENCE ENCYCLOPEDIA
Projects (Week 1 C) · Sovereign Documentation
⚑ 100% SILICON & COGNITIVE DEPTH
AYMAN ELMASRY
Computational Creative Director · AI Prompt Engineer
Founder of Ayman Elmasry LLC
πŸ”’ ⚑ AEL Sovereign Seal (Active Verification)
{
  "ael_seal": "AEL CS Encyclopedia β€” Β© Ayman Elmasry",
  "owner": "Ayman Elmasry",
  "legal_entities": [
    "Ayman Elmasry LLC (UAE)",
    "Ayman Elmasry Advertising & Marketing (Egypt)"
  ],
  "section": "06_Projects (Week 1 C)",
  "syllabus_source": "Harvard CS50x (Projects Architectural Design)",
  "methodology": "8-Stage Sub-Silicon Execution Paradigm",
  "system_version": "v3.0"
}

πŸ›οΈ Architecture of Classic CS50 Problem Sets

The problem sets of Week 1 in C represent the student's primary rite of passage into bare-metal, algorithmically intensive software engineering (Problem-Solving Architecture). In this wing, we deconstruct the underlying algorithmic paradigms and execution strategies for three seminal projects within the CS50x curriculum:

===================================================================================
                       WEEK 1 C - PROJECTS ARCHITECTURE
===================================================================================

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚ 1. MARIO (Less & More Comfortable)                     β”‚ ──> Nested Loops & Alignment
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ 2. CASH (Less Comfortable)                             β”‚ ──> The Greedy Algorithm
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
  β”‚ 3. CREDIT (More Comfortable)                           β”‚ ──> Luhn's Algorithm & Modulo Math
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

===================================================================================

🧱 1. The Mario Pyramid Architecture (Mario - Less & More Comfortable)

Inspired by the structural brick blocks of Super Mario Bros, this project requires students to print ascending and descending text-based pyramids in the console terminal. The core architectural goals are mastering the geometric arithmetic of nested loops (Nested Loops) and enforcing strict user input validation (Input Validation).

Mario - Less Comfortable (Single Right-Aligned Pyramid)

Construct a single right-aligned pyramid with a user-defined height spanning between 1 and 8. For any zero-indexed row i, leading spaces is spaces = height - i - 1 and hashes is hashes = i + 1.

   #  (3 spaces, 1 hash)
  ##  (2 spaces, 2 hashes)
 ###  (1 space,  3 hashes)
####  (0 spaces, 4 hashes)

Mario - More Comfortable (Double Adjacent Pyramids)

Construct two adjacent, opposing pyramids separated by a fixed static gap of exactly two spaces .

#include <cs50.h>
#include <stdio.h>

int main(void)
{
    int height;
    // 1. Input Validation (Enforce integer between 1 and 8)
    do
    {
        height = get_int("Height: ");
    }
    while (height < 1 || height > 8);

    // 2. Master Loop for Rows
    for (int i = 0; i < height; i++)
    {
        // Print leading spaces
        for (int spaces = 0; spaces < height - i - 1; spaces++)
        {
            printf(" ");
        }

        // Print left pyramid hashes
        for (int hashes = 0; hashes <= i; hashes++)
        {
            printf("#");
        }

        // Print middle static gap
        printf("  ");

        // Print right pyramid hashes
        for (int hashes = 0; hashes <= i; hashes++)
        {
            printf("#");
        }

        // Move to next row
        printf("\n");
    }
}

πŸͺ™ 2. The Change Machine & The Greedy Algorithm (Cash)

In the Cash problem set, engineers architect an optimized coin-dispensation engine calculated to return the absolute minimum number of coins to a customer.

===================================================================================
                       THE GREEDY ALGORITHM PIPELINE
===================================================================================

  [ Cents Input: e.g., 68Β’ ]
            β”‚
            β”œβ”€β–Ί Quarters (25Β’) ──> 68 / 25 = 2 (Remainder: 18Β’)
            β”œβ”€β–Ί Dimes (10Β’)    ──> 18 / 10 = 1 (Remainder: 8Β’)
            β”œβ”€β–Ί Nickels (5Β’)   ──> 8 / 5   = 1 (Remainder: 3Β’)
            └─► Pennies (1Β’)   ──> 3 / 1   = 3 (Remainder: 0Β’)
            
  [ Total Minimum Coins = 2 + 1 + 1 + 3 = 7 Coins ]

===================================================================================

πŸ’‘ Deconstructing the Greedy Paradigm (Greedy Algorithm)

A greedy algorithm executes the local optimal decision at each distinct stage of execution, without concern for long-term algorithmic implications. For standard American coin denominations (25Β’, 10Β’, 5Β’, 1Β’), mathematical proofs demonstrate that this greedy heuristic reliably achieves the global optimum.


πŸ’³ 3. Verification Engine: Luhn's Algorithm (Credit)

The Credit problem set represents an advanced engineering challenge requiring the architectural verification of credit card numbers (Visa, MasterCard, American Express) utilizing Luhn's Checksum Algorithm (Luhn's Algorithm).

===================================================================================
                       LUHN'S CARD VERIFICATION ALGORITHM
===================================================================================

  [ Card Number: e.g., 4 0 1 2 8 8 8 8 8 8 8 8 8 8 8 3 ] (Length 16, Starts 4 -> Visa)
            β”‚
            β”œβ”€β–Ί 1. Multiply every second digit from right by 2 (Add product digits)
            β”œβ”€β–Ί 2. Add sum of digits that weren't multiplied
            └─► 3. If total modulo 10 == 0, Card is VALID.

===================================================================================

1. Standard Enterprise Industry Classifications

2. Deconstructing Luhn's Architectural Checksum

  1. Stage One: Commencing from the second-to-last digit and traversing leftward, multiply every second digit by 2. (If the resulting product yields a two-digit number e.g., 6 * 2 = 12, do not add 12 to the sum. Instead, split the product and sum its individual digits 1 + 2 = 3).
  2. Stage Two: Sum all remaining digits that were skipped (not multiplied by 2).
  3. Stage Three: Combine both sums. If the terminal digit of the aggregate total equals zero (total_sum % 10 == 0), the checksum is mathematically validated.

3. Modulo Math & Low-Level Extraction

Because high-level string manipulation is restricted in early C problem sets, engineers must parse card digits directly from numerical types. By executing modulo division card % 10, the system extracts the trailing rightmost digit. Executing standard division card /= 10 permanently truncates the trailing digit. Given the 16-digit magnitude of credit card numbers, developers must allocate 64-bit long variables to prevent catastrophic overflow (Overflow).